package com.gxa.order.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.gxa.common.base.RespResult;
import com.gxa.order.constants.Constant;
import com.gxa.order.dto.CommentDto;
import com.gxa.order.entity.AccommodationOrder;
import com.gxa.order.mapper.AccommodationOrderAppMapper;
import com.gxa.order.service.AccommodationOrderAppService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
* @author 陈书睿
* @description 针对表【accommodation_order】的数据库操作Service实现
* @createDate 2023-04-10 13:53:30
*/
@Service
public class AccommodationOrderAppServiceImpl extends ServiceImpl<AccommodationOrderAppMapper, AccommodationOrder>
    implements AccommodationOrderAppService {


    private final AccommodationOrderAppMapper accommodationOrderMapper;

    @Autowired
    public AccommodationOrderAppServiceImpl(AccommodationOrderAppMapper accommodationOrderMapper) {
        this.accommodationOrderMapper = accommodationOrderMapper;
    }

//    @Resource
//    private RabbitTemplate rabbitTemplate;

    @Override
    public RespResult updateOrderStatusByOrderNo(Long order_num, String status) {
        if (status.equals("b")) {
            accommodationOrderMapper.updataOrderStatusByOrderNo2(order_num, new Date(), Constant.ORDER_PAY);
            return RespResult.success("支付成功");
        }
        if (status.equals("a")) {
            accommodationOrderMapper.updataOrderStatusByOrderNo1(order_num, new Date(), Constant.ORDER_CREATE);
            return RespResult.success("下单成功");
        }
        if (status.equals("c")) {
            accommodationOrderMapper.updataOrderStatusByOrderNo3(order_num,Constant.ORDER_REFUND);
            return RespResult.success("退款成功");
        }
        if (status.equals("d")) {
            accommodationOrderMapper.updataOrderStatusByOrderNo4(order_num,Constant.ORDER_CANCEL);
            return RespResult.success("取消订单成功");
        }
        if (status.equals("e")) {
            accommodationOrderMapper.updataOrderStatusByOrderNo5(order_num,new Date(),Constant.ORDER_HOTEL);
            return RespResult.success("入住成功");
        }
            return RespResult.error("状态错误");
    }

    @Override
    public RespResult addComment(CommentDto commentDto) {
        accommodationOrderMapper.addComment(commentDto);
        //int id=commentDto.getAccommodation_comments_id();
        return RespResult.success("添加成功");
    }

    @Override
    public int addImg(String s, int id) {
        return accommodationOrderMapper.addImg(s,id);
    }

    @Override
    public RespResult selectpayorder(Long order_num) {
        return null;
    }

//    @Override
//    public RespResult selectpayorder(Long order_num) {
//        return accommodationOrderMapper.selectpayorder(order_num);
//    }

}




